package com.balck.ioc;

import com.balck.ioc.module.User;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import javax.jws.soap.SOAPBinding;

/**
 * 注入方法
 */
public class Main {
    public static void main(String[] args) {
        ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
        m1(ctx);
        m2(ctx);

    }

    //调用set方法注入
    private static void m2(ClassPathXmlApplicationContext ctx) {
        User u4 = ctx.getBean("user2",User.class);
        System.out.println("u4="+u4);
    }

    //构造方法注入
    private static void m1(ClassPathXmlApplicationContext ctx) {
        User u1 = (User)ctx.getBean("user");
        User u2 = ctx.getBean("user",User.class);
        //User u3 = ctx.getBean(User.class);
        System.out.println("u1="+u1);
        System.out.println("u2="+u2);
        //System.out.println("u3="+u3);
    }
}
